package com.curvebreakers.wheresmystuff.model;


import com.curvebreakers.wheresmystuff.R;

import android.content.*;
import android.view.*;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class EntryAdapter extends ArrayAdapter<Entry> {	
	
	public EntryAdapter(Context context, int textViewResourceId) {
		super(context, textViewResourceId);
	}
	
	public View getView(int position, View convertView, ViewGroup parent){

		View v = convertView;

		if (v == null) {
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(R.layout.listrow_entry, null);
		}

		Entry e = getItem(position);
		
		if (e != null) {
			TextView titleView = (TextView)v.findViewById(R.id.entry_row_title);
			TextView dateView = (TextView)v.findViewById(R.id.entry_row_date);
			TextView catDescView = (TextView)v.findViewById(R.id.entry_row_cat_desc);
			View statusBlock = (View)v.findViewById(R.id.entry_row_status_block);
			titleView.setText(e.getTitle());
			catDescView.setText(e.getEntryType().getAdjective()+" "+e.getCategory().getNoun()+" - "+e.getDescription());
			dateView.setText(e.getDateString());
			if (e.isResolved())
				statusBlock.setBackgroundColor(getContext().getResources().getColor(R.color.orange));
			else
				statusBlock.setBackgroundColor(getContext().getResources().getColor(R.color.green));
				
		}
		
		return v;
	}
}
